cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"



set more off, perm
use "models_data0828.dta", clear
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg


	
gen lendogsq=ltied_OECD_gdp^2
xtivreg2 gdppcg (ltied_OECD_gdp=lIV_main_agg) lendogsq period* if BDperiod>=3 , fe robust cluster(rec_id) first
reg ltied_OECD_gdp lIV_main_agg period* recdummy* , robust cluster(rec_id)
gen lsample=1 if e(sample)

label var gdppcg "Growth in GDP per capita"            
label var ltied_OECD_gdp "Tied Aid/GDP (lagged)"       
label var luntied_OECD_gdp "Untied Aid/GDP (lagged)"
label var lcom_total_OECD_gdp "Total-tied Aid/GDP (lagged)"
label var lninitGDPpc "Baseline per capita income (log)"   
label var ethnofrac "Ethnolinguistic fractionalization"  
label var assassinations "Assassinations"
label var lbroadmoney_gdp "M2/GDP (lagged)"  
label var easia "East Asia"   
label var ssa "Sub-Saharan Africa"
label var policy_newper "Public policy"    
label var democ_RB "Institutional quality"        
label var govfrac "Donor fractionalization"     
label var totalprob13 "Probability of receiving aid"     
label var all_aid_gdp "Total aid per capita"
label var trade_gdp "Trade/GDP"
label var strataid_av5 "Strategic aid per capita"

estpost sum gdppcg ltied_OECD_gdp luntied_OECD_gdp lcom_total_OECD_gdp ///
lninitGDPpc ethnofrac assassinations lbroadmoney_gdp  ///
ssa easia policy_newper democ_RB  govfrac totalprob13 all_aid_gdp trade_gdp strataid_av5  if lsample==1
esttab using "G:\My Drive\tied aid\Replication\Results\descriptives.tex", label cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))") width(1.0\hsize) nomtitle nonumber replace




set more off, perm
use "models_data0828.dta", clear
keep lninitGDPpc assassinations ethnofrac ethnicassass lbroadmoney_gdp tied_OECD_gdp untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ssa easia recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp govfrac totalprob13 democ_RB policy_newper
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg


	
gen lendogsq=ltied_OECD_gdp^2
xtivreg2 gdppcg (ltied_OECD_gdp=lIV_main_agg) lendogsq period* if BDperiod>=3 , fe robust cluster(rec_id) first
reg ltied_OECD_gdp lIV_main_agg period* recdummy* , robust cluster(rec_id)
gen lsample=1 if e(sample)
predict laidresidual, resid
reg gdppcg ltied_OECD_gdp lendogsq laidresidual period* recdummy*
	est store lH1		
	
gen lunendogsq=luntied_OECD_gdp^2
xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>=3 , fe robust cluster(rec_id) first
reg luntied_OECD_gdp lIV_main_agg period* recdummy* , robust cluster(rec_id)
predict lunaidresidual, resid
reg gdppcg luntied_OECD_gdp lunendogsq lunaidresidual period* recdummy* 
	est store lH2	
	suest lH1 lH2, cluster(rec_id)
test [lH1_mean]ltied_OECD_gdp== [lH2_mean]luntied_OECD_gdp
*             chi2(  1) =    5.04
*         Prob > chi2 =    0.0247



		
gen lrestendogsq=lcom_total_OECD_gdp^2
xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>=3 , fe robust cluster(rec_id) first
reg lcom_total_OECD_gdp lIV_main_agg period* recdummy* , robust cluster(rec_id)
predict lrestresidual, resid
reg gdppcg lcom_total_OECD_gdp lrestendogsq lrestresidual period* recdummy* 
	est store lH3
		suest lH1 lH3, cluster(rec_id)
test [lH1_mean]ltied_OECD_gdp== [lH3_mean]lcom_total_OECD_gdp
*            chi2(  1) =    4.55
*         Prob > chi2 =    0.0329


*** Tied
cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear

keep lninitGDPpc assassinations ethnofrac ethnicassass broadmoney_gdp tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp democ_RB  ssa easia policy_newper
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg

global bdtv lninitGDPpc assassinations ethnicassass ethnofrac l.broadmoney_gdp ssa easia
		gen endog=.
		gen endogsq=.
		gen IV=.
		gen IVsq=.	
		gen interact=.
		gen linteract=.

		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
	gen ltied_OECD_gdp2=ltied_OECD_gdp^2	
		*Column 1 
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		*xtreg gdppcg endog endogsq $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg endog endogsq $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		*xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
	
		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
	*	xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
			   
		esttab OLS*  using "Results\Clemens_1990pcGDP.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq lninitGDPpc assassinations ethnicassass L.broadmoney_gdp) ///
				varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic*Assassinations" L.broadmoney_gdp "M2/GDP (lagged)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 3) label("Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* Ictry_*   
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*           chi2(  1) =    6.03
*         Prob > chi2 =    0.0141
reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* Ictry_*   
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*          chi2(  1) =    6.01
*         Prob > chi2 =    0.0142
				
*** No baseline GDP pc
cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear

keep lninitGDPpc assassinations ethnofrac ethnicassass broadmoney_gdp tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp democ_RB  ssa easia policy_newper
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg

global bdtv assassinations ethnicassass ethnofrac l.broadmoney_gdp 
		gen endog=.
		gen endogsq=.
		gen IV=.
		gen IVsq=.	
		gen interact=.
		gen linteract=.

		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
	gen ltied_OECD_gdp2=ltied_OECD_gdp^2	
		*Column 1 
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		*xtreg gdppcg endog endogsq $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg endog endogsq $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		*xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
	
		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
	*	xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
			   
		esttab OLS*  using "Results\Clemens_1990pcGDP_nobaseline.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq lninitGDPpc assassinations ethnicassass L.broadmoney_gdp) ///
				varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				lninitGDPpc "Log Initial GDP pc"  assassinations "Assassinations" ethnicassass "Ethnic*Assassinations" L.broadmoney_gdp "M2/GDP (t-1)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 3) label("Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* Ictry_*   
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*             chi2(  1) =    5.85
*         Prob > chi2 =    0.0156

reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* Ictry_*   
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*          chi2(  1) =    5.69
*         Prob > chi2 =    0.0170


*** Public policy
cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear

keep lninitGDPpc assassinations ethnofrac ethnicassass broadmoney_gdp tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp democ_RB  ssa easia policy_newper
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg

global bdtv lninitGDPpc assassinations ethnicassass ethnofrac l.broadmoney_gdp ssa easia policy_newper
		gen endog=.
		gen endogsq=.
		gen IV=.
		gen IVsq=.	
		gen interact=.
		gen linteract=.

		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
	gen ltied_OECD_gdp2=ltied_OECD_gdp^2	
		*Column 1 
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		*xtreg gdppcg endog endogsq $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg endog endogsq $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		*xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
	
		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
	*	xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
			   
		esttab OLS*  using "Results\Clemens_1990pcGDP_subsample.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq lninitGDPpc assassinations ethnicassass L.broadmoney_gdp) ///
				varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic x Assassinations" L.broadmoney_gdp "M2/GDP (lagged)" policy_newper "Public policy") ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 3) label("Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* Ictry_*   
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*           chi2(  1) =    6.45
*         Prob > chi2 =    0.0111
reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* Ictry_*   
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*          chi2(  1) =    6.60
*         Prob > chi2 =    0.0102				


***
*** Trade


cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"



set more off, perm
use "models_data0828.dta", clear



keep lninitGDPpc assassinations ethnicassass broadmoney_gdp tied_OECD untied_OECD com_total_OECD tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ethnofrac lbroadmoney_gdp trade_gdp democ_RB policy_newper ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp all_aid_gdp all_aid_pc l5lstrataid_av
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg


gen lendogsq=ltied_OECD_gdp^2
gen lunendogsq=luntied_OECD_gdp^2
gen lrestendogsq=lcom_total_OECD_gdp^2


*OLS
global bdtv lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp
		gen endog=.
		gen endogsq=.
		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
    gen ltied_OECD_gdp2=ltied_OECD_gdp^2
	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		xtreg gdppcg endog endogsq $bdtv period* trade_gdp , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 trade_gdp $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		

		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 trade_gdp $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
   
		esttab OLS*  using "Results\Clemens_1990pcGDP_trade.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq lninitGDPpc assassinations ethnicassass L.broadmoney_gdp) ///
				varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				trade_gdp "Trade / GDP" lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic x Assassinations" lbroadmoney_gdp "M2/GDP (lagged)" trade_gdp "Trade/GDP" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 0 3) label( "Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)				
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 trade_gdp $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 trade_gdp $bdtv period* Ictry_* 
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*           chi2(  1) =    5.67
*         Prob > chi2 =    0.0173

reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 trade_gdp $bdtv period* Ictry_*  
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*          chi2(  1) =    5.48
*         Prob > chi2 =    0.0193				



*************
***
*** Strategic Aid


cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"



set more off, perm
use "models_data0828.dta", clear



keep lninitGDPpc assassinations ethnicassass broadmoney_gdp tied_OECD untied_OECD com_total_OECD tied_OECD_gdp democ_RB policy_newper ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ethnofrac lbroadmoney_gdp ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp all_aid_gdp all_aid_pc l5lstrataid_av
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg


gen lendogsq=ltied_OECD_gdp^2
gen lunendogsq=luntied_OECD_gdp^2
gen lrestendogsq=lcom_total_OECD_gdp^2


*OLS
global bdtv lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp 
		gen endog=.
		gen endogsq=.
		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
    gen ltied_OECD_gdp2=ltied_OECD_gdp^2
	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		xtreg gdppcg endog endogsq $bdtv period* l5lstrataid_av , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 l5lstrataid_av $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		

		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 l5lstrataid_av $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
   
		esttab OLS*  using "Results\Clemens_1990pcGDP_strategicaid.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq lninitGDPpc assassinations ethnicassass lbroadmoney_gdp) ///
				varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				l5lstrataid_av "Strategic Aid" lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic x Assassinations" lbroadmoney_gdp "M2/GDP (lagged)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 0 3) label( "Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)				
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 l5lstrataid_av $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 l5lstrataid_av $bdtv period* Ictry_* 
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*             chi2(  1) =    5.78
*        Prob > chi2 =    0.0162


reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 l5lstrataid_av $bdtv period* Ictry_*  
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*     chi2(  1) =    9.68
 *        Prob > chi2 =    0.0019
			


***** Total Aid
*** Tied
cap local DIR = "G:\My Drive\tied aid\Replication\"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear

keep lninitGDPpc assassinations ethnofrac ethnicassass lbroadmoney_gdp tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp all_aid_pc democ_RB policy_newper
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg
gen lall_aid_pc=l.all_aid_pc

global bdtv lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp 
		gen endog=.
		gen endogsq=.
		gen IV=.
		gen IVsq=.	
		gen interact=.
		gen linteract=.

		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
    gen ltied_OECD_gdp2=ltied_OECD_gdp^2
	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
    gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2

			
****Total aid per capita			
		qui xtivreg2 gdppcg (ltied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		xtreg gdppcg endog endogsq lall_aid_pc $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 lall_aid_pc $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		
		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 lall_aid_pc $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
			   
		esttab OLS*  using "Results\Clemens_1990pcGDP_total.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq luntied_OECD_gdp luntied_OECD_gdp2 lcom_total_OECD_gdp lcom_total_OECD_gdp2 lninitGDPpc assassinations ethnicassass lbroadmoney_gdp) ///
				varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				lall_aid_pc "Total aid per capita" lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic x Assassinations" lbroadmoney_gdp "M2/GDP (lagged)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 3) label("Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 lall_aid_pc $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 lall_aid_pc $bdtv period* Ictry_* 
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*           chi2(  1) =    5.35
*         Prob > chi2 =    0.0207
reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 lall_aid_pc $bdtv period* Ictry_*  
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*          chi2(  1) =    5.47
*         Prob > chi2 =    0.0193				
				
	
	

				
****************************Table 3: Aid and Growth, 1974-2013, IV*****************************
		
		***Panels A and B***
cap local DIR = "G:\My Drive\tied aid\Replication\"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear

keep lninitGDPpc assassinations ethnicassass broadmoney_gdp tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg


	
gen lendogsq=ltied_OECD_gdp^2		
gen endog=ltied_OECD_gdp
gen endogsq=ltied_OECD_gdp^2
gen IV=lIV_main_agg
	
		*Column 1 
		xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		xtreg endog lIV_main_agg period* if e(sample), fe robust cluster(rec_id)
			est store c1_fst		
		xtreg endog endogsq period* if e(sample), fe robust cluster(rec_id)
			est store c1_fs
		
		set more off
			cap program drop CFAboot
			program CFAboot, eclass
			cap drop aidresidual
			tempname b V
			tempvar aidresidual  
			xtivreg2 gdppcg (endog=IV) period* if BDperiod>=3 , fe robust cluster(rec_id) first   
			reg endog IV period* recdummy*  if lsample==1, robust cluster(rec_id)
			predict aidresidual, resid
			xtreg gdppcg endog endogsq aidresidual period*  if lsample==1, fe robust cluster(rec_id)		
			matrix `b' = e(b)
			ereturn post `b'
		end
		
		bootstrap _b, reps(500) seed(999) cluster(recdummy*) idcluster(rec_id)  : CFAboot
		estadd local nobs="849"
		estadd local lag="Yes"
		est store c1_boot
		
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
gen luntied_OECD_gdp2=luntied_OECD_gdp^2

		xtreg luntied_OECD_gdp lIV_main_agg period* if e(sample), fe robust cluster(rec_id)
			est store c2_fst
		xtreg luntied_OECD_gdp luntied_OECD_gdp2 period* if e(sample), fe robust cluster(rec_id)
			est store c2_fs
		set more off
			cap program drop CFAboot
			program CFAboot, eclass
			cap drop aidresidual
			tempname b V
			tempvar aidresidual  
			xtivreg2 gdppcg (luntied_OECD_gdp=IV) period* if BDperiod>=3 , fe robust cluster(rec_id) first   
			reg luntied_OECD_gdp IV period* recdummy* if lsample==1, robust cluster(rec_id)
			predict aidresidual, resid
			xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 aidresidual period* if lsample==1, fe robust cluster(rec_id)		
			matrix `b' = e(b)
			ereturn post `b'
		end
		
		bootstrap _b, reps(500) seed(999) cluster(recdummy*) idcluster(rec_id) nodots nowarn : CFAboot
		estadd local nobs="849"
		estadd local lag="Yes"
		est store c2_boot
		
			*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
xtreg lcom_total_OECD_gdp lIV_main_agg period* if e(sample), fe robust cluster(rec_id)
			est store c3_fst
xtreg lcom_total_OECD_gdp lcom_total_OECD_gdp2 period* if e(sample), fe robust cluster(rec_id)
			est store c3_fs
		set more off
			cap program drop CFAboot
			program CFAboot, eclass
			cap drop aidresidual
			tempname b V
			tempvar aidresidual  
			xtivreg2 gdppcg (lcom_total_OECD_gdp=IV) period* if BDperiod>=3 , fe robust cluster(rec_id) first   
			reg lcom_total_OECD_gdp IV period* recdummy* if lsample==1, robust cluster(rec_id)
			predict aidresidual, resid
			xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 aidresidual period* if lsample==1, fe robust cluster(rec_id)		
			matrix `b' = e(b)
			ereturn post `b'
		end
		
		bootstrap _b, reps(500) seed(999) cluster(recdummy*) idcluster(rec_id) nodots nowarn : CFAboot
		estadd local nobs="768"
		estadd local lag="Yes"
		est store c3_boot
	
		*Second Stage 		 
		esttab c1_boot c2_boot c3_boot ///
			using "Results\Dreher_1990pcGDP.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop( _cons period* aidresidual) order(endog endogsq ) varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total - Tied Aid$^2$/GDP") ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag nobs fstat pval, fmt(0 0 3 3 3) ///
				label("Aid lagged" "\hline Number of obs."  )) postfoot( \hline)   

				esttab c1_fst c1_fs c2_fst c2_fs c3_fst c3_fs ///
			using "Results\Dreher_1990pcGDP_Line1.tex", replace fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01) ///
			varlabel(endog "Tied Aid" ) mlabel(none) style(tex) nonumbers nolines nogaps stats() noabbr noobs 
				
	
			est drop *
			

*** 5YR period


*** 5YR period
cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear

keep rec lninitGDPpc assassinations ethnofrac ethnicassass lbroadmoney_gdp tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp all_aid_pc democ_RB policy_newper
keep if year>=1990
drop period*

gen BDperiod_new=.
replace BDperiod_new=0 if year==1985|year==1986|year==1987|year==1988|year==1989
replace BDperiod_new=1 if year==1990|year==1991|year==1992|year==1993|year==1994
replace BDperiod_new=2 if year==1995|year==1996|year==1997|year==1998|year==1999
replace BDperiod_new=3 if year==2000|year==2001|year==2002|year==2003|year==2004
replace BDperiod_new=4 if year==2005|year==2006|year==2007|year==2008|year==2009
replace BDperiod_new=5 if year==2010|year==2011|year==2012|year==2013|year==2014
replace BDperiod_new=6 if year==2015|year==2016|year==2017|year==2018
replace BDperiod_new=. if BDperiod==.
quietly tabulate BDperiod_new, generate(period)
duplicates drop rec_id BDperiod_new, force
xtset rec_id BDperiod_new
gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg

* Clemens table

global bdtv lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp 

	gen ltied_OECD_gdp2=ltied_OECD_gdp^2	
		*Column 1 
		xtivreg2 gdppcg (ltied_OECD_gdp=lIV_main_agg) period* , fe robust cluster(rec_id) 
		gen lsample=1 if e(sample)
		*xtreg gdppcg endog endogsq $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		*xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
	
		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
	*	xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
			   
		esttab OLS*  using "Results\Clemens_1990pcGDP_5YR.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(ltied_OECD_gdp ltied_OECD_gdp2 lninitGDPpc ///
				assassinations ethnicassass lbroadmoney_gdp) ///
				varlabel(ltied_OECD_gdp "Tied Aid/GDP" ltied_OECD_gdp2 "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic x Assassinations" lbroadmoney_gdp "M2/GDP (lagged)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 3) label("Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate rec_id, gen(Ictry_)
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* Ictry_*   
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*           chi2(  1) =    5.10
*         Prob > chi2 =    0.0239
reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* Ictry_*   
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*          chi2(  1) =    4.91
*         Prob > chi2 =    0.0267			


			
***** ODA

cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"



set more off, perm
use "models_data0828.dta", clear



keep lninitGDPpc assassinations ethnicassass broadmoney_gdp tied_OECD untied_OECD com_total_OECD tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ethnofrac lbroadmoney_gdp democ_RB policy_newper ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp all_aid_gdp all_aid_pc
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg

gen lendogsq=ltied_OECD_gdp^2
gen lunendogsq=luntied_OECD_gdp^2
gen lrestendogsq=lcom_total_OECD_gdp^2

sum com_total_OECD_gdp
*keep if com_total_OECD_gdp>1
*keep if com_total_OECD_gdp>5
keep if com_total_OECD_gdp>7.428

*OLS
global bdtv lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp 
		gen endog=.
		gen endogsq=.
		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
    gen ltied_OECD_gdp2=ltied_OECD_gdp^2
	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		xtreg gdppcg endog endogsq $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		

		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2  $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
  
		esttab OLS*  using "Results\Clemens_1990pcGDP_ODA.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq luntied_OECD_gdp luntied_OECD_gdp2 lcom_total_OECD_gdp lcom_total_OECD_gdp2 lninitGDPpc assassinations ethnicassass lbroadmoney_gdp) ///
				varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic x Assassinations" lbroadmoney_gdp "M2/GDP (lagged)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 0 3) label("Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)				
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* Ictry_* 
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
	** at mean, > 7.4
*            chi2(  1) =   14.78
*         Prob > chi2 =    0.0001



reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* Ictry_*  
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
	** at mean, >7.4
*            chi2(  1) =   13.82
*         Prob > chi2 =    0.0002

			
	
*************************
*************************	
*** Instrumental variable
cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear

keep lninitGDPpc assassinations ethnicassass broadmoney_gdp tied_OECD untied_OECD com_total_OECD tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ethnofrac lbroadmoney_gdp democ_RB policy_newper ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp all_aid_gdp all_aid_pc
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg

sum com_total_OECD_gdp
*keep if com_total_OECD_gdp>1
*keep if com_total_OECD_gdp>5
keep if com_total_OECD_gdp>7.428
	
gen lendogsq=ltied_OECD_gdp^2
xtivreg2 gdppcg (ltied_OECD_gdp=lIV_main_agg) period* if BDperiod>=3 , fe robust cluster(rec_id) first
reg ltied_OECD_gdp lIV_main_agg period* recdummy* , robust cluster(rec_id)
predict laidresidual, resid
reg gdppcg ltied_OECD_gdp lendogsq laidresidual period* recdummy*  
	est store lH1t	
	
gen lunendogsq=luntied_OECD_gdp^2
xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>=3 , fe robust cluster(rec_id) first
reg luntied_OECD_gdp lIV_main_agg period* recdummy* , robust cluster(rec_id)
predict lunaidresidual, resid
reg gdppcg luntied_OECD_gdp lunendogsq lunaidresidual period* recdummy* 
	est store lH2t
	suest lH1t lH2t, cluster(rec_id)
test [lH1t_mean]ltied_OECD_gdp== [lH2t_mean]luntied_OECD_gdp
** at mean, >7.4
*           chi2(  1) =    11.51
*         Prob > chi2 =    0.0007

 
gen lrestendogsq=lcom_total_OECD_gdp^2
xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>=3 , fe robust cluster(rec_id) first
reg lcom_total_OECD_gdp lIV_main_agg period* recdummy* , robust cluster(rec_id)
predict lrestresidual, resid
reg gdppcg lcom_total_OECD_gdp lrestendogsq lrestresidual period* recdummy* 
	est store lH3t
		suest lH1t lH3t, cluster(rec_id)
test [lH1t_mean]ltied_OECD_gdp== [lH3t_mean]lcom_total_OECD_gdp
** at mean, >7.4
*           chi2(  1) =    11.36
*         Prob > chi2 =    0.0008	

			
****************************Table 3: Aid and Growth, 1974-2013, IV*****************************
		
		***Panels A and B***
	    gen endog=.
		gen endogsq=.
		xtset rec_id BDperiod	
	
    replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
	replace IV=lIV_main_agg
		*Column 1 
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)

		set more off
			cap program drop CFAboot
			program CFAboot, eclass
			cap drop aidresidual
			tempname b V
			tempvar aidresidual  
			xtivreg2 gdppcg (endog=IV) period* if BDperiod>=3 , fe robust cluster(rec_id) first   
			reg endog IV period* recdummy*  if lsample==1, robust cluster(rec_id)
			predict aidresidual, resid
			xtreg gdppcg endog endogsq aidresidual period* if lsample==1 , fe robust cluster(rec_id)		
			matrix `b' = e(b)
			ereturn post `b'
		end
		
		bootstrap _b, reps(500) seed(999) cluster(recdummy*) idcluster(rec_id) nodots nowarn : CFAboot
		estadd local nobs="328"
		estadd local lag="Yes"
		est store c1_boot
		
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
gen luntied_OECD_gdp2=l.untied_OECD_gdp^2
		set more off
			cap program drop CFAboot
			program CFAboot, eclass
			cap drop aidresidual
			tempname b V
			tempvar aidresidual  
			xtivreg2 gdppcg (luntied_OECD_gdp=IV) period* if BDperiod>=3 , fe robust cluster(rec_id) first   
			reg luntied_OECD_gdp IV period* recdummy* if lsample==1, robust cluster(rec_id)
			predict aidresidual, resid
			xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 aidresidual period* if lsample==1 , fe robust cluster(rec_id)		
			matrix `b' = e(b)
			ereturn post `b'
		end
		
		bootstrap _b, reps(500) seed(999) cluster(recdummy*) idcluster(rec_id) nodots nowarn : CFAboot
		estadd local nobs="243"
		estadd local lag="Yes"
		est store c2_boot
		
			*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
gen lcom_total_OECD_gdp2=l.com_total_OECD_gdp^2
		set more off
			cap program drop CFAboot
			program CFAboot, eclass
			cap drop aidresidual
			tempname b V
			tempvar aidresidual  
			xtivreg2 gdppcg (lcom_total_OECD_gdp=IV) period* if BDperiod>=3 , fe robust cluster(rec_id) first   
			reg lcom_total_OECD_gdp IV period* recdummy* if lsample==1, robust cluster(rec_id)
			predict aidresidual, resid
			xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 aidresidual period* if lsample==1, fe robust cluster(rec_id)		
			matrix `b' = e(b)
			ereturn post `b'
		end
		
		bootstrap _b, reps(500) seed(999) cluster(recdummy*) idcluster(rec_id) nodots nowarn : CFAboot
		estadd local nobs="170"
		estadd local lag="Yes"
		est store c3_boot
	
		*Second Stage 		 
		esttab c1_boot c2_boot c3_boot ///
			using "Results\Dreher_1990pcGDP_ODA_7.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop( _cons period* aidresidual) order(endog endogsq ) varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total - Tied Aid$^2$/GDP") ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats (lag nobs fstat pval, fmt(0 0 3 3 3) ///
				label("Aid lagged" "\hline Number of obs."  )) postfoot( \hline)   
				
			est drop *			

***** No Aid Dummy

cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"



set more off, perm
use "models_data0828.dta", clear



keep lninitGDPpc assassinations ethnicassass broadmoney_gdp tied_OECD untied_OECD com_total_OECD tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ethnofrac lbroadmoney_gdp democ_RB policy_newper ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp all_aid_gdp all_aid_pc
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg

gen tied_NAD=0
replace tied_NAD=1 if tied_OECD==0|tied_OECD==.
gen ltied_NAD=l.tied_NAD
gen untied_NAD=0
replace untied_NAD=1 if untied_OECD==0|untied_OECD==.
gen luntied_NAD=l.untied_NAD
gen all_NAD=0
replace all_NAD=1 if com_total_OECD==0|com_total_OECD==.
gen lall_NAD=l.all_NAD
gen lendogsq=ltied_OECD_gdp^2
gen lunendogsq=luntied_OECD_gdp^2
gen lrestendogsq=lcom_total_OECD_gdp^2


*OLS
global bdtv lninitGDPpc assassinations ethnicassass  lbroadmoney_gdp 
		gen endog=.
		gen endogsq=.
		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
    gen ltied_OECD_gdp2=ltied_OECD_gdp^2
	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		xtreg gdppcg endog endogsq ltied_NAD $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"
estadd local NAD "Yes"
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 luntied_NAD $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		estadd local NAD "Yes"
		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 lall_NAD $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
		estadd local NAD "Yes"	   
		esttab OLS*  using "Results\Clemens_1990pcGDP_NAD.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq luntied_OECD_gdp luntied_OECD_gdp2 lcom_total_OECD_gdp lcom_total_OECD_gdp2 lninitGDPpc assassinations ethnicassass lbroadmoney_gdp) ///
				varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic x Assassinations" lbroadmoney_gdp "M2/GDP (lagged)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag NAD N r2_a , fmt(0 0 0 3) label("No Aid Dummy" "Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)				
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 ltied_NAD $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 luntied_NAD $bdtv period* Ictry_* 
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*           chi2(  1) =    5.60
*         Prob > chi2 =    0.0179

reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 lall_NAD $bdtv period* Ictry_*  
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*          chi2(  1) =    5.57
*         Prob > chi2 =    0.0183				
	

			
*************

			
*************
***
*** No lagged vars


cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"



set more off, perm
use "models_data0828.dta", clear



keep lninitGDPpc assassinations ethnicassass broadmoney_gdp tied_OECD untied_OECD com_total_OECD tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ethnofrac lbroadmoney_gdp democ_RB policy_newper ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp all_aid_gdp all_aid_pc
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg


gen lendogsq=ltied_OECD_gdp^2
gen lunendogsq=luntied_OECD_gdp^2
gen lrestendogsq=lcom_total_OECD_gdp^2


*OLS
global bdtv lninitGDPpc assassinations ethnicassass ethnofrac broadmoney_gdp democ_RB policy_newper
		gen endog=.
		gen endogsq=.
		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
    gen ltied_OECD_gdp2=ltied_OECD_gdp^2
	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		xtreg gdppcg endog endogsq $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"
estadd local NAD "Yes"
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		estadd local NAD "Yes"
		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
		estadd local NAD "Yes"	   
		esttab OLS*  using "Results\Clemens_1990pcGDP_nolags.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq lninitGDPpc assassinations ethnicassass L.broadmoney_gdp) ///
				varlabel( endog "Tied Aid/GDP" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				lninitGDPpc "Log Initial GDP pc"  assassinations "Assassinations" ethnicassass "Ethnic*Assassinations" broadmoney_gdp "M2/GDP" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag NAD N r2_a , fmt(0 0 0 3) label( "Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)				
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2  $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* Ictry_* 
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*           chi2(  1) =    5.78
*         Prob > chi2 =    0.0163

reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2  $bdtv period* Ictry_*  
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*          chi2(  1) =    6.10
*         Prob > chi2 =    0.0135				
		
		
*** Pop
cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear

keep lninitGDPpc assassinations ethnofrac ethnicassass broadmoney_gdp tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp democ_RB  ssa easia policy_newper tied_OECD untied_OECD pop commitments_OECD all_aid_pc
gen tied_pc=tied_OECD/pop
gen untied_pc=untied_OECD/pop
gen com_pop=commitments_OECD/pop
label var all_aid_pc "Total aid per capita"

keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_pop
gen luntied_OECD_gdp=l.untied_pop
gen lcom_total_OECD_gdp=l.com_pop
gen lIV_main_agg=l.IV_main_agg

global bdtv lninitGDPpc assassinations ethnicassass ethnofrac l.broadmoney_gdp ssa easia
		gen endog=.
		gen endogsq=.
		gen IV=.
		gen IVsq=.	
		gen interact=.
		gen linteract=.

		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
	gen ltied_OECD_gdp2=ltied_OECD_gdp^2	
		*Column 1 
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		*xtreg gdppcg endog endogsq $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg endog endogsq $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		*xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
	
		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
	*	xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
			   
		esttab OLS*  using "Results\Clemens_1990pcPOP.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq lninitGDPpc assassinations ethnicassass L.broadmoney_gdp) ///
				varlabel( endog "Tied Aid/pop" endogsq "Tied Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				lcom_total_OECD_gdp "Total-Tied Aid/GDP" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$/GDP" ///
				lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic*Assassinations" L.broadmoney_gdp "M2/GDP (lagged)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 3) label("Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* Ictry_*   
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*           chi2(  1) =    6.03
*         Prob > chi2 =    0.0141
reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* Ictry_*   
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*          chi2(  1) =    6.01
*         Prob > chi2 =    0.0142
						
						
*Partial Tied Aid$^2$/GDP
cap local DIR = "C:\Users\paula\Dropbox\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"



set more off, perm
use "models_data0828.dta", clear
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod


keep lninitGDPpc assassinations ethnofrac ethnicassass lbroadmoney_gdp tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp democ_RB  ssa easia policy_newper GDPcurrentUSD ptied_OECD
keep if year>=1990
xtset rec_id BDperiod

gen ptied_OECD_gdp=ptied_OECD*100*1000000/GDPcurrentUSD
gen lptied_OECD_gdp=l.ptied_OECD_gdp
gen ltied_OECD_gdp=l.tied_OECD_gdp
gen ltiedptied=ltied_OECD_gdp+lptied_OECD_gdp
gen ltiedptied_sq=ltiedptied^2
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen ltotal_tiedptied=lcom_total_OECD_gdp-ltiedptied
gen ltotal_tiedptied_sq=ltotal_tiedptied^2
gen lIV_main_agg=l.IV_main_agg

global bdtv lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp ssa easia
		gen endog=.
		gen endogsq=.
		gen IV=.
		gen IVsq=.	
		gen interact=.
		gen linteract=.

		xtset rec_id BDperiod

	replace endog=ltiedptied
	replace endogsq=ltiedptied_sq
	*gen ltied_OECD_gdp2=ltied_OECD_gdp^2	
		*Column 1 
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		*xtreg gdppcg endog endogsq $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg endog endogsq $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		*xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
	
		*Column 3 
		qui xtivreg2 gdppcg (ltotal_tiedptied=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
	*	xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg ltotal_tiedptied ltotal_tiedptied_sq $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
			   
		esttab OLS*  using "Results\TiedpTied.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq luntied_OECD_gdp luntied_OECD_gdp2 ltotal_tiedptied ltotal_tiedptied_sq lninitGDPpc assassinations ethnicassass lbroadmoney_gdp) ///
				varlabel( endog "Tied + Partially Tied Aid/GDP" endogsq "Tied + Partially Aid$^2$/GDP" ///
				luntied_OECD_gdp "Untied Aid/GDP" luntied_OECD_gdp2 "Untied Aid$^2$/GDP" ///
				ltotal_tiedptied "Total - Tied + Partially Tied Aid/GDP" ltotal_tiedptied_sq "Total - Tied + Partially Tied Aid$^2$/GDP" ///
				lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic x Assassinations" lbroadmoney_gdp "M2/GDP (lagged)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 3) label("Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)
reg gdppcg ltiedptied ltiedptied_sq $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* Ictry_*   
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltiedptied== [m2_mean]luntied_OECD_gdp
*           chi2(  1) =    3.73
*         Prob > chi2 =    0.0536
reg gdppcg ltotal_tiedptied ltotal_tiedptied_sq $bdtv period* Ictry_*   
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltiedptied== [m3_mean]ltotal_tiedptied
*          chi2(  1) =    3.79
*         Prob > chi2 =    0.0516

* Population scaling

use "C:\Users\paula\Dropbox\tied aid\Replication\no_scaling.dta", replace

encode recipient, gen(recipcode)
xtset recipcode year
replace tied_cons=0 if tied_cons==.
replace untied_cons=0 if untied_cons==.
replace commitments_cons=0 if commitments_cons==.
keep if year>=1990
g commitments_av5_L=(L1.commitments_cons+L2.commitments_cons+L3.commitments_cons+L4.commitments_cons+L5.commitments_cons)/5
g tied_av5_L=(L1.tied_cons+L2.tied_cons+L3.tied_cons+L4.tied_cons+L5.tied_cons)/5
g untied_av5_L=(L1.untied_cons+L2.untied_cons+L3.untied_cons+L4.untied_cons+L5.untied_cons)/5

merge 1:1 recipient_year using "C:\Users\paula\Dropbox\tied aid\Replication\models_data07132023.dta"


keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod
keep if pop>1000000

gen tied_av5_Lbn=tied_av5_L*1000000/pop
gen untied_av5_Lbn=untied_av5_L*1000000/pop
gen commitments_av5_Lbn=commitments_av5_L*1000000/pop
gen ltied_OECD_gdp=l.tied_av5_Lbn
gen luntied_OECD_gdp=l.untied_av5_Lbn
gen lcom_total_OECD_gdp=l.commitments_av5_Lbn-l.tied_av5_Lbn
gen lIV_main_agg=l.IV_main_agg

global bdtv lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp ssa easia
		gen endog=.
		gen endogsq=.
		gen IV=.
		gen IVsq=.	
		gen interact=.
		gen linteract=.

		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
	gen ltied_OECD_gdp2=ltied_OECD_gdp^2	
		*Column 1 
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		*xtreg gdppcg endog endogsq $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg endog endogsq $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		*xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
	
		*Column 3 
		qui xtivreg2 gdppcg (lcom_total_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		*xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* , fe robust cluster(rec_id)  
		est store OLS3	  
		estadd local lag "Yes"	
			   
		esttab OLS*  using "Results\Pop_scaling.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog endogsq luntied_OECD_gdp luntied_OECD_gdp2 lcom_total_OECD_gdp lcom_total_OECD_gdp2 lninitGDPpc assassinations ethnicassass lbroadmoney_gdp) ///
				varlabel( endog "Tied Aid" endogsq "Tied Aid$^2$" ///
				luntied_OECD_gdp "Untied Aid" luntied_OECD_gdp2 "Untied Aid$^2$" ///
				lcom_total_OECD_gdp "Total-Tied Aid" lcom_total_OECD_gdp2 "Total-Tied Aid$^2$" ///
				lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic x Assassinations" lbroadmoney_gdp "M2/GDP (lagged)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 3) label("Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

drop recdummy* 
quietly tabulate BDperiod, generate(_I)
quietly tabulate rec_id, gen(Ictry_)
reg gdppcg ltied_OECD_gdp ltied_OECD_gdp2 $bdtv period* Ictry_* 
est sto m1
reg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* Ictry_*   
est sto m2
	suest m1 m2, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m2_mean]luntied_OECD_gdp
*           chi2(  1) =    6.03
*         Prob > chi2 =    0.0141
reg gdppcg lcom_total_OECD_gdp lcom_total_OECD_gdp2 $bdtv period* Ictry_*   
est sto m3
	suest m1 m3, cluster(rec_id)
	test [m1_mean]ltied_OECD_gdp== [m3_mean]lcom_total_OECD_gdp
*          chi2(  1) =    6.01
*         Prob > chi2 =    0.0142


* Percent Aid


*** Tied
cap local DIR = "G:\My Drive\tied aid\Replication\"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear

gen total_aid=untied_OECD+ptied_OECD+tied_OECD
gen ptied=tied_OECD/total_aid*100
gen puntied=untied_OECD/total_aid*100


keep lninitGDPpc assassinations ethnofrac ethnicassass lbroadmoney_gdp tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp democ_RB  ssa easia policy_newper GDPcurrentUS total_aid ptied puntied

keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod


gen ltied_OECD_gdp=l.ptied
gen luntied_OECD_gdp=l.puntied
gen lcom_total_OECD_gdp=l.total_aid
gen lIV_main_agg=l.IV_main_agg

global bdtv lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp ssa easia
		gen endog=.
		gen endogsq=.
		gen IV=.
		gen IVsq=.	
		gen interact=.
		gen linteract=.

		xtset rec_id BDperiod

	replace endog=ltied_OECD_gdp
	replace endogsq=ltied_OECD_gdp^2
	gen ltied_OECD_gdp2=ltied_OECD_gdp^2	
		*Column 1 
		qui xtivreg2 gdppcg (endog=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		gen lsample=1 if e(sample)
		*xtreg gdppcg endog endogsq $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg c.endog##c.lcom_total_OECD_gdp $bdtv period* , fe robust cluster(rec_id)  
		est store OLS1	  
		estadd local lag "Yes"

	gen luntied_OECD_gdp2=luntied_OECD_gdp^2
	
		*Column 2 
		qui xtivreg2 gdppcg (luntied_OECD_gdp=lIV_main_agg) period* if BDperiod>3 , fe robust cluster(rec_id) first savefirst savefprefix(lagfs1) 
		replace lsample=1 if e(sample)
		*xtreg gdppcg luntied_OECD_gdp luntied_OECD_gdp2 $bdtv period* if lsample==1, fe robust cluster(rec_id)  
		xtreg gdppcg c.luntied_OECD_gdp##c.lcom_total_OECD_gdp $bdtv period* , fe robust cluster(rec_id)  
		est store OLS2	  
		estadd local lag "Yes"		
		
	gen lcom_total_OECD_gdp2=lcom_total_OECD_gdp^2
	

			   
		esttab OLS1 OLS2  using "Results\percentaid.tex", fragment booktabs se(3) b(3) star starlevels(* 0.10 ** 0.05 *** 0.01)  replace  ///
				drop(_cons period* )  order(endog luntied_OECD_gdp lcom_total_OECD_gdp lninitGDPpc assassinations ethnicassass lbroadmoney_gdp) ///
				varlabel( endog "Tied Aid pc Total Aid" ///
				luntied_OECD_gdp "Untied Aid pc Total Aid"  ///
				lcom_total_OECD_gdp "Total Aid" ///
				lninitGDPpc "Baseline per capita income (log)"  assassinations "Assassinations" ethnicassass "Ethnic x Assassinations" lbroadmoney_gdp "M2/GDP (lagged)" ) ///
				mlabel(none) style(tex)  nolines nogaps nonumbers  ///
				stats(lag N r2_a , fmt(0 0 3) label("Aid lagged" "\hline Number of obs." "Adj. R-Squared" ))  noabbr 

				
xtreg gdppcg c.ltied_OECD_gdp##c.lcom_total_OECD_gdp $bdtv period* , fe robust cluster(rec_id)  
gen e = e(sample)
drop if e == 0
sum ltied_OECD_gdp, det
sum lcom_total_OECD_gdp, det
margins, at((means)_all ltied_OECD_gdp = (0(5)100) ) post


marginsplot,graphregion(color(white)) title("")  xtitle("Tied Aid (% of Total Aid lagged)")				

graph save "Graph" "G:\My Drive\tied aid\Replication\Results\TotalTied_margins.gph", replace
graph export "G:\My Drive\tied aid\Replication\Results\totaltied_margins.pdf", as(pdf) name("Graph") replace

cap local DIR = "G:\My Drive\tied aid\Replication\"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear

gen total_aid=untied_OECD+ptied_OECD+tied_OECD
gen ptied=tied_OECD/total_aid*100
gen puntied=untied_OECD/total_aid*100


keep lninitGDPpc assassinations ethnofrac ethnicassass lbroadmoney_gdp tied_OECD_gdp ///
untied_OECD_gdp gdppcg BDperiod rec_id rec year IV_main_agg period* ///
recdummy* xconst_av5 dem_acc corruption_icrg l5rentsp_av com_total_OECD_gdp democ_RB  ssa easia policy_newper GDPcurrentUS total_aid ptied puntied

keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.ptied
gen luntied_OECD_gdp=l.puntied
gen lcom_total_OECD_gdp=l.total_aid

xtreg gdppcg c.luntied_OECD_gdp##c.lcom_total_OECD_gdp $bdtv period* , fe robust cluster(rec_id)  
gen e = e(sample)
drop if e == 0
sum luntied_OECD_gdp, det
sum lcom_total_OECD_gdp, det
margins, at((means)_all luntied_OECD_gdp = (0(5)100) ) post


marginsplot,graphregion(color(white) ) title("") xtitle("Untied Aid (% of Total Aid lagged)")

graph save "Graph" "G:\My Drive\tied aid\Replication\Results\TotalUntied_margins.gph", replace
graph export "G:\My Drive\tied aid\Replication\Results\totaluntied_margins.pdf", as(pdf) name("Graph") replace
graph combine "G:\My Drive\tied aid\Replication\Results\TotalTied_margins.gph" "G:\My Drive\tied aid\Replication\Results\TotalUntied_margins.gph"

graph export "G:\My Drive\tied aid\Replication\Results\TotalMargins.pdf", as(pdf) name("Graph") replace

* Margins Plot

 

cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg


label var gdppcg "GDP/Pop Growth"            
label var ltied_OECD_gdp "Tied Aid % GDP (lagged)"       
label var luntied_OECD_gdp "Untied Aid % GDP (lagged)"
label var lcom_total_OECD_gdp "Total-tied Aid/GDP (lagged)"
label var lninitGDPpc "Baseline per capita income (log)"   
label var ethnofrac "Ethnolinguistic fractionalization"  
label var assassinations "Assassinations"
label var lbroadmoney_gdp "M2/GDP (lagged)"  
label var easia "East Asia"   
label var ssa "Sub-Saharan Africa"
label var policy_newper "Public policy"    
label var democ_RB "Institutional quality"        
label var govfrac "Donor fractionalization"     
label var totalprob13 "Probability of receiving aid"     
label var all_aid_gdp "Total aid per capita"
label var trade_gdp "Trade/GDP"
label var strataid_av5 "Strategic aid per capita"


gen ltied_OECD_gdpsq=ltied_OECD_gdp^2
xtreg gdppcg c.ltied_OECD_gdp##c.ltied_OECD_gdp lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp ssa easia period* , fe robust cluster(rec_id)  
gen e = e(sample)
drop if e == 0
sum ltied_OECD_gdp, det
margins, at((means)_all ltied_OECD_gdp = (0(.5)20)) post 


marginsplot,graphregion(color(white)) title("") yline(0) 




/*marginsplot,  plot1opts(lcolor(black) lpattern(solid) lwidth(medthick) mstyle(none)) ///
ci1opts(lcolor(black) lpattern(shortdash) msymbol(none)) recastci(rconnected) ///
xdimension(ltied_OECD_gdp)  graphregion(color(white)) ytitle("") title("") ///
l2title("GDP/Pop Growth", size(4) color(black)) xtitle("Tied Aid (% GDP lagged)", size(4))  ///
ylabel(, angle(horizontal))  graphregion(color(white)) ///
ylabel(-2(1)6, labsize(medium) nogrid notick) xscale(range(0[1]20) titlegap(4)) legend(off) xlabel(0(5)20) yline(0)*/
graph save "Graph" "G:\My Drive\tied aid\Replication\Results\Tied_margins.gph", replace
graph export "G:\My Drive\tied aid\Replication\Results\tied_margins.pdf", as(pdf) name("Graph") replace


cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg


	
gen lendogsq=ltied_OECD_gdp^2
xtivreg2 gdppcg (ltied_OECD_gdp=lIV_main_agg) lendogsq period* if BDperiod>=3 , fe robust cluster(rec_id) first
reg ltied_OECD_gdp lIV_main_agg period* recdummy* , robust cluster(rec_id)
gen lsample=1 if e(sample)

label var gdppcg "GDP/Pop Growth"            
label var ltied_OECD_gdp "Tied Aid % GDP (lagged)"       
label var luntied_OECD_gdp "Untied Aid % GDP (lagged)"
label var lcom_total_OECD_gdp "Total-tied Aid/GDP (lagged)"
label var lninitGDPpc "Baseline per capita income (log)"   
label var ethnofrac "Ethnolinguistic fractionalization"  
label var assassinations "Assassinations"
label var lbroadmoney_gdp "M2/GDP (lagged)"  
label var easia "East Asia"   
label var ssa "Sub-Saharan Africa"
label var policy_newper "Public policy"    
label var democ_RB "Institutional quality"        
label var govfrac "Donor fractionalization"     
label var totalprob13 "Probability of receiving aid"     
label var all_aid_gdp "Total aid per capita"
label var trade_gdp "Trade/GDP"
label var strataid_av5 "Strategic aid per capita"

gen luntied_OECD_gdpsq=luntied_OECD_gdp^2
xtreg gdppcg c.luntied_OECD_gdp##c.luntied_OECD_gdp lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp ssa easia period* , fe robust cluster(rec_id)  
gen e = e(sample)
drop if e == 0
sum luntied_OECD_gdp, det
margins, at((means)_all luntied_OECD_gdp = (0(5)57)) post 
marginsplot, graphregion(color(white)) title("") yline(0)


graph save "Graph" "G:\My Drive\tied aid\Replication\Results\Untied_margins.gph", replace
graph export "G:\My Drive\tied aid\Replication\Results\untied_margins.pdf", as(pdf) name("Graph") replace
graph combine "G:\My Drive\tied aid\Replication\Results\Tied_margins.gph" "G:\My Drive\tied aid\Replication\Results\Untied_margins.gph"

graph export "G:\My Drive\tied aid\Replication\Results\Margins.pdf", as(pdf) name("Graph") replace


*********************
*Both margins in one plot1opts


cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg


	
gen lendogsq=ltied_OECD_gdp^2
xtivreg2 gdppcg (ltied_OECD_gdp=lIV_main_agg) lendogsq period* if BDperiod>=3 , fe robust cluster(rec_id) first
reg ltied_OECD_gdp lIV_main_agg period* recdummy* , robust cluster(rec_id)


label var gdppcg "GDP/Pop Growth"            
label var ltied_OECD_gdp "Tied Aid % GDP (lagged)"       
label var luntied_OECD_gdp "Untied Aid % GDP (lagged)"
label var lcom_total_OECD_gdp "Total-tied Aid/GDP (lagged)"
label var lninitGDPpc "Baseline per capita income (log)"   
label var ethnofrac "Ethnolinguistic fractionalization"  
label var assassinations "Assassinations"
label var lbroadmoney_gdp "M2/GDP (lagged)"  
label var easia "East Asia"   
label var ssa "Sub-Saharan Africa"
label var policy_newper "Public policy"    
label var democ_RB "Institutional quality"        
label var govfrac "Donor fractionalization"     
label var totalprob13 "Probability of receiving aid"     
label var all_aid_gdp "Total aid per capita"
label var trade_gdp "Trade/GDP"
label var strataid_av5 "Strategic aid per capita"

gen XXX=ltied_OECD_gdp
xtreg gdppcg c.XXX##c.XXX lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp ssa easia period* , fe robust cluster(rec_id)  
gen e = e(sample)
*drop if e == 0
sum XXX, det
margins, at((means)_all XXX = (0(2)20)) post saving(m1, replace)
drop XXX
gen XXX=luntied_OECD_gdp
xtreg gdppcg c.XXX##c.XXX lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp ssa easia period* , fe robust cluster(rec_id)  
*gen e = e(sample)
*drop if e == 0
sum XXX, det
margins, at((means)_all XXX = (0(2)20)) post saving(m2, replace)

*combomarginsplot m1 m2, xtitle("Aid a % of GDP") label("Tie Aid" "United Aid") scheme(stmono2)

combomarginsplot m1 m2, xtitle("Aid a % of GDP") label("Tie Aid" "United Aid") scheme(stmono2) fileci1opts(recast(rarea) fcolor(ebblue%50))  fileci2opts(recast(rarea) fcolor(eltblue%50)) //addplot(hist ltied_OECD_gdp, yaxis(2) xaxis(2) fcolor(ebblue%50) lcolor(black) || hist luntied_OECD_gdp, yaxis(2) xaxis(2) fcolor(ebg%50) lcolor(black))

graph export "G:\My Drive\tied aid\Replication\Results\Margins.pdf", as(pdf) name("Graph") replace

*********************
*Both margins in one plot1opts


cap local DIR = "G:\My Drive\tied aid\Replication"  /*change relative path to the directory where the files are located 		*/
cap cd "`DIR'"

set more off, perm
use "models_data0828.dta", clear
keep if year>=1990
drop period1 period2 period3 period4 period5 period6 
xtset rec_id BDperiod

gen ltied_OECD_gdp=l.tied_OECD_gdp
gen luntied_OECD_gdp=l.untied_OECD_gdp
gen lcom_total_OECD_gdp=l.com_total_OECD_gdp
gen lIV_main_agg=l.IV_main_agg


	
gen lendogsq=ltied_OECD_gdp^2
xtivreg2 gdppcg (ltied_OECD_gdp=lIV_main_agg) lendogsq period* if BDperiod>=3 , fe robust cluster(rec_id) first
reg ltied_OECD_gdp lIV_main_agg period* recdummy* , robust cluster(rec_id)


label var gdppcg "GDP/Pop Growth"            
label var ltied_OECD_gdp "Tied Aid % GDP (lagged)"       
label var luntied_OECD_gdp "Untied Aid % GDP (lagged)"
label var lcom_total_OECD_gdp "Total-tied Aid/GDP (lagged)"
label var lninitGDPpc "Baseline per capita income (log)"   
label var ethnofrac "Ethnolinguistic fractionalization"  
label var assassinations "Assassinations"
label var lbroadmoney_gdp "M2/GDP (lagged)"  
label var easia "East Asia"   
label var ssa "Sub-Saharan Africa"
label var policy_newper "Public policy"    
label var democ_RB "Institutional quality"        
label var govfrac "Donor fractionalization"     
label var totalprob13 "Probability of receiving aid"     
label var all_aid_gdp "Total aid per capita"
label var trade_gdp "Trade/GDP"
label var strataid_av5 "Strategic aid per capita"

gen XXX=ltied_OECD_gdp
xtreg gdppcg c.XXX##c.XXX lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp ssa easia period* , fe robust cluster(rec_id)  
gen e = e(sample)
*drop if e == 0
sum XXX, det
margins, at((means)_all XXX = (0(.5)6)) post saving(m1, replace)
drop XXX
gen XXX=luntied_OECD_gdp
xtreg gdppcg c.XXX##c.XXX lninitGDPpc assassinations ethnicassass ethnofrac lbroadmoney_gdp ssa easia period* , fe robust cluster(rec_id)  
*gen e = e(sample)
*drop if e == 0
sum XXX, det
margins, at((means)_all XXX = (0(.5)6)) post saving(m2, replace)

*combomarginsplot m1 m2, xtitle("Aid a % of GDP") label("Tie Aid" "United Aid") scheme(stmono2)

combomarginsplot m1 m2, xtitle("Aid a % of GDP") label("Tie Aid" "United Aid") scheme(stmono2) fileci1opts(recast(rarea) fcolor(ebblue%50))  fileci2opts(recast(rarea) fcolor(ebg%50)) 

graph export "G:\My Drive\tied aid\Replication\Results\Margins_focus.pdf", as(pdf) name("Graph") replace
			